import java.util.ArrayList;

public class Main {


    private static double testSet(Set<String> set, String filename) {
        long startTime = System.currentTimeMillis();

        System.out.println(filename);
        ArrayList<String> words = new ArrayList<>();
        if (FileOperation.readFile(filename, words)) {
            System.out.println("Total words: " + words.size());
            for (String word : words) {
                set.add(word);
            }
            System.out.println("Total different words: " + set.getSize());
        }

        long endTime = System.currentTimeMillis();
        return (endTime - startTime) / 1000.0;
    }

    public static void main(String[] args) {
        String filename = "pride-and-prejudice.txt";

        // 时间复杂度 O(logn)
        // 存在最差的情况，会出现 O(n)，当数据按顺序进入时，二分搜索树会退化成链表
        BSTSet<String> bstSet = new BSTSet<>();
        double time1 = testSet(bstSet, filename);
        System.out.println("BST Set: " + time1 + "s");

        System.out.println();

        // 时间复杂度 O(n)
        LinkedListSet<String> linkedListSet = new LinkedListSet<>();
        double time2 = testSet(linkedListSet, filename);
        System.out.println("Linked List Set: " + time2 + "s");

        System.out.println();

        AVLSet<String> avlSet = new AVLSet<>();
        double time3 = testSet(avlSet, filename);
        System.out.println("AVL Set: " + time3 + "s");
    }

}
